<?php 
$weekarr = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
$week = $weekarr[date("w")];
?>
<div id="intermediary" class="indexcontentdiv">
    <div class="positiondiv">
        <table>
            <tr>
                <td class="td-left">
                    <img src="<?=base_url()?>resource/img/home_ico.png" width="21" height="17">
                    Setting > <a href="<?=base_url()?>user/employee">Employee</a> > Employee Edit
                </td>
                <td class="td-right">
                    <img src="<?=base_url()?>resource/img/menu2.png" width="27" height="24">Today is <?=$week?>,<?=date('M d,Y')?>
                </td>
            </tr>
        </table>
    </div>
    <div class="input-div">
        <form action="<?=base_url('user/employee_detail/'.$employee['id'])?>" method="post" onkeydown="if(event.keyCode==13)return false;" onsubmit="return checkform()">
            <table>
                <tr><td colspan="2"><h3>.Employee Detail</h3></td></tr>
                <tr><td class="nametd">IC NO:</td><td><input type="text" name="sn" value="<?=$employee['sn']?>"/></td></tr>
                <tr><td class="nametd">Name:</td>
                    <td>
                        <input type="text" name="name" value="<?=$employee['name']?>"/>
                        <span id="namemsg" class="err">*</span>
                    </td>
                </tr>
                <tr>
                    <td class="nametd">Department:</td>
                    <td>
                        <select name="department" id="department" style="width:100px">
                            <option value="0">-select-
                            <option value="1">Office
                            <option value="2">Marketing
                            <option value="3">Logistics
                        </select>
                        <span id="departmentmsg" class="err">*</span>
                    </td>
                </tr>
                <tr><td class="nametd">Position:</td><td><input type="text" name="position" value="<?=$employee['position']?>"/></td></tr>
                <tr>
                    <td class="nametd">Work Pass Holder:</td><td>
                        <select name="workpassholder" id="workpassholder">
                            <option value="0">-select-
                            <option value="1">PR
                            <option value="2">EP
                            <option value="3">WP
                            <option value="4">SP
                            <option value="5">SC
                            <option value="6">DP
                        </select>
                    </td>
                </tr>
                <tr><td class="nametd">Join Date:</td><td><input type="text" name="joindate" id="joindate" style="width:120px;" value="<?=$employee['joindate']?>"/></td></tr>
                <tr><td class="nametd">Birthday:</td><td><input type="text" name="birthday" id="birthday" style="width:120px;" value="<?=$employee['birthday']?>"/></td></tr>
                <tr><td class="nametd">Username:</td><td>
                        <select name="userid" id="userid" style="width:120px;">
                            <option value="<?=isset($user['id'])?$user['id']:''?>"><?=isset($user['username'])?$user['username']:''?>
                            <?php foreach ($leisureuser as $value) { ?>
                            <option value="<?=$value['id']?>"><?=$value['username']?>
                            <?php }?>
                        </select>
                        <span id="useridmsg" class="err">*</span>
                    </td>
                </tr>
                <tr><td class="nametd">Password:</td>
                    <td>
                        <input type="text" name="password" id="password" value="<?=isset($user['password'])?$user['password']:''?>"/>
                        <span id="passwordmsg" class="err">*</span>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="submit" value="Save"/>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>
<script>
$("#department").val("<?=$employee['department']?>");
$("#workpassholder").val("<?=$employee['workpassholder']?>");

var data = new Array();
<?php foreach ($leisureuser as $key => $value) {?>
    data[<?=$key?>] = new Array();
    data[<?=$key?>]['id'] = "<?=$value['id']?>";
    data[<?=$key?>]['username'] = "<?=$value['username']?>";
    data[<?=$key?>]['password'] = "<?=$value['password']?>";
<?php }?>

$("#userid").change(function(){
    var id = $(this).val();
    var flag = false;
    for(var i = 0;i < data.length;i++){
        if(id == data[i]['id']){
            flag = true;
            $("#password").val(data[i]['password']);
        }
    }
    if(!flag){
        $("#password").val("<?=isset($user['password'])?$user['password']:''?>");
    }
});
    
$("input[type='button']").click(function(){
    $("input[name='username']").val('');
    $("input[name='password']").val('');
    $("#role").val(0);
});

$('#birthday').datetimepicker({
    format:"Y-m-d",      //格式化日期
    timepicker:false,    //关闭时间选项
});

$('#joindate').datetimepicker({
    format:"Y-m-d",      //格式化日期
    timepicker:false,    //关闭时间选项
});

function checkform(){
    var flag = true;
    var name = $.trim($("input[name='name']").val());
    if(name == ''){
        flag = false;
        $("#namemsg").html("Name can not be empty!");
    }else{
        $("#namemsg").html("*");
    }
    
    var department = $("#department").val();
    if(department == 0){
        flag = false;
        $("#departmentmsg").html("Please select department!");
    }else{
        $("#departmentmsg").html("*");
    }
    
    var password = $.trim($("input[name='password']").val());
    if(password == ''){
        flag = false;
        $("#passwordmsg").html("Password can not be empty!");
    }else{
        $("#passwordmsg").html("*");
    }
    
    return flag;
}
</script>
　